﻿using WYJ.SDK.Core.Json;
using WYJ.SDK.Web;

internal static class App
{
    internal static Launcher Launcher { get; }
    internal static AppSetting AppSettings { get; set; }

    static App()
    {
        Launcher = JsonLoader.LoadFrom<Launcher>("appsettings.json")!;
#if RELEASE
        Launcher.Environment = "Production";
#endif
        AppSettings = JsonLoader.LoadFrom<AppSetting>($"appsettings.{Launcher.Environment}.json")!;
    }

    internal static WebApplicationBuilder Launch(string[] args)
    {
        WebApplicationOptions WebApplicationOptions = new WebApplicationOptions
        {
            EnvironmentName = Launcher.Environment,
            WebRootPath = AppSettings.WebRootPath,
            Args = [.. args, "--urls", AppSettings.Urls]
        };
        WebApplicationBuilder builder = WebApplication.CreateBuilder(WebApplicationOptions);
        builder.Services.AddCors(Launcher.CorsPolicyDic);
        return builder;
    }
}

